//
//  SQSocket.h
//  pai
//
//  Created by pro on 14-11-14.
//  Copyright (c) 2014年 linjunjing. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AsyncSocket.h"

//auction system cmds
/*********************************************
 define     message type
 **********************************************/

#define ACS_MSG_ECHO       8888  //heartbeat

#define ACS_MSG_REGISTER   8010  //

#define ACS_MSG_USER_MOD   8012  //change password

#define ACS_MSG_INPOUR     8014  //inpour

#define ACS_MSG_AUCT       8016  //make an auct

#define ACS_MSG_EXCHANGE   8020  //make an exchange

#define ACS_MSG_CHECKCODE  8022 //get a checkcode

#define ACS_MSG_ADD_ADDR   8024  //add address

#define ACS_MSG_SET_ADDR   8026 //set a deliver address

//#define ACS_MSG_DEVICE_TOKEN  8028  //


#define ACS_MSG_LOGIN      1011  //

//#define ACS_MSG_USER_LIST  1013 //

#define ACS_MSG_LOGOUT  1015    //logout








#define ACS_MSG_APP_OFFLINE   1100 //app offline

#define ACS_MSG_APP_WAKE    1101 //wake

#define ACS_MSG_UNREAD_NOTES     1012 //pull UNREAD_NOTES



#define ACS_MSG_AUCT_LIST 1017 //list goods for auction

#define ACS_MSG_AUCT_DETAIL 1020 // detail


#define ACS_MSG_PRODUCT_DETAIL 1022 //detail of product
#define ACS_MSG_PRODUCT_LIST 1019 //product list
#define ACS_MSG_PRODUCT_SEARCH 1018 //search products
#define ACS_MSG_MY_CHECK 1030 //my ....




#define ACS_CHECK_TIME_OUT  30 //

/*********************************************
 define     error code
 **********************************************/
#define ACS_SUCCESS            9999

#define ACS_ERR_LOGIN          3000
#define ACS_ERR_INVALID_USER   3002
#define ACS_ERR_PASSWORD       3004

#define ACS_ERR_SIGNUP         3010
#define ACS_ERR_USER_DUPLICATE      3011
#define ACS_ERR_USER_MOD       3012

#define ACS_ERR_CHECK_CODE     3013
#define ACS_ERR_CHECK_EXPIRED  3014
#define ACS_ERR_PHONE_DUPLICATE 3015
#define ACS_ERR_CHECK_INVALID 3016 //invald cellphone or checkcode
#define ACS_ERR_USER_INVALID  3018

#define ACS_ERR_UNREAD_NOTE   3070



#define ACS_ERR_GET_PRODUCT    3020


/******************************************
 note from MIS
 **************************************/

#define ACS_MSG_AUCTION      9001
#define ACS_MSG_ORDER_CHECK  9002

typedef struct acs_base_t{
	
	int  msgtype;
    
	int len;
	
	int error;//0:success.
	
}acs_base_t;

#define ACS_BASE_LEN      sizeof(acs_base_t)



//set a deliver address

#define ACS_ERROR_INVALID_ADDR  3080

#define ACS_ERROR_INVALID_SERIAL 3081

#define ACS_ERROR_SET_ADDR  3082
typedef struct set_addr_t{
	acs_base_t base;
	int address_id;
	char serialnum[32];
	
}set_addr_t;

//request
typedef struct pull_unread_note_t{
	acs_base_t base;
	char username[32+1];
}pull_unread_note_t;

//ack
typedef struct ack_pull_unread_note_t{
	acs_base_t base;
    
    //'$' for item separator;'#' for field separator
	char body[1024];
	
}ack_pull_unread_note_t;

typedef struct on_off_line_t{
	acs_base_t base;
	char username[32+1];
}on_off_line_t;

typedef struct check_code_t {
	
	acs_base_t base;
	char cellphone[32+1];
	
}check_code_t;

#define ACS_ERR_CHECKCODE_INVALID  3050
#define ACS_ERR_CHECKCODE_WAIT     3051
typedef struct user_mod_t {
    acs_base_t base;
    char cellphone[32+1];
    char newpwd[32+1];
    char checkcode[6+1];
}user_mod_t ;

#define ACS_ERR_USER_LOCK 3052//user was locked

typedef struct user_login_t {
	
	acs_base_t base;
	
	int  devicetype;//0:apple iphone,1:android
	
	char userid[32+1];/*username or cellphone*/
	
	char userpwd[32+1];
	
	char appver[32+1];
	
	char devicetoken[128];
	
} user_login_t;

typedef struct user_logout_t {
	
	acs_base_t base;
	
	char userid[32+1];
    
} user_logout_t;

typedef struct user_login_ack_t {
	
	acs_base_t base;
	
	int ballance;
	int points;
	char usename[32+1];
	char cellphone[32+1];
    
}user_login_ack_t;


#define ACS_ERR_SIGN_ERRINFO   3083//the information posted was not qualified
typedef struct user_signup_t {
	
	acs_base_t base;
    
	char userid[32+1];
	
	char userpwd[32+1];
	
	char cellphone[32+1];
	
	char checkcode[6+1];
	
}user_signup_t;


typedef struct product_sku_t{
	
	int price;
	int point;
	int stock;
	char sku_code[32];
	char sku_name[256];
	char attri_values[64];
	
}product_sku_t;

typedef struct product_detail_t{
	acs_base_t base;
	int product_id;
	
}product_detail_t;

typedef struct ack_product_detail_t{
	acs_base_t base;
	int count;//the num of sku
	char* sku_list;
}ack_product_detail_t;

typedef struct product_item_t {
	int price;
	int points;
	int stock;
	int product_id;
	char intro[256+1];
	char title[128+1];
	char category[32+1];
    //	char attri_keys[64];
    //	char* product_skus;
	
}product_item_t;

#define ACS_ERR_SKU_CODE  3063
typedef struct ack_auct_sku_detail_t{
	acs_base_t base;
	int price;
    int cost;
    int state;
    char attri_keys[64];
    char attri_values[64];
	
}ack_auct_sku_detail_t;


typedef struct auct_sku_detail_t{
	acs_base_t base;
	char sku_code[32];
}auct_sku_detail_t;

typedef struct auct_sku_item_t{
    
	int status;
	int stdate;
	int eddate;
	char sku_name[256];
	char sku_code[32];
	char serialnum[32];
    
}auct_sku_item_t;


typedef struct auct_list_t {
	acs_base_t base;
    
	int count; //request: the num intend to get;ack:actual num
	int offset; //
	char   *list;
}auct_list_t;


typedef struct product_search_t {
	acs_base_t base;
	int type;//1:goods for auction(keytype=0,2);2 products.(keytype=1,3)
	int count; // actual num(max=10)
	int offset; //
	int keytype;//0:title;1:sku_code;2serialnum.3 catagory
	char keyword[32+1];
}product_search_t;

typedef struct ack_product_search_t{
	acs_base_t base;
	int type;
	int count;
	char *list;
}ack_product_search_t;


typedef struct category_list_t{
}category_list_t;


#define ACS_ERR_AUCT_DUPLICATE   3030//
#define ACS_ERR_AUCT_NOBANLLANCE 3032//
#define ACS_ERR_AUCT_LIMIT       3031//
#define ACS_ERR_AUCT_NOSTART     3034//
#define ACS_ERR_AUCT_PRICE   3036// Invalid price
#define ACS_ERR_AUCT_BIZ       3038 //biz fail
#define ACS_ERR_AUCT_HIT      3040//hit

typedef struct biz_auction_t {  //make an auction
	
	acs_base_t base;
	
	int  auctprice;
	
	char username[32+1];
	
	char serialnum[32+1];//serial num of the auction
	
}biz_auction_t;


#define ACS_ERR_EXCHANGE    3042//
#define ACS_ERR_INVALID_SKU 3044//
#define ACS_ERR_POINTS_OVER      3046//
#define ACS_ERR_NOPOINTS    3048//

typedef struct biz_exchange_t{
	acs_base_t base;
	int addressid;
	int price;
	int points;
	char username[32+1];
	char sku[32+1];
	
}biz_exchange_t;

#define ACS_ERR_AMT_INVALID  3060
#define ACS_ERR_INPOUR       3062//fail
typedef struct biz_inpour_t{
	acs_base_t base;
	int  channel;//10:alipay;11:wechat
	char amt[32+1];//amount of funds.unit:cent
	char userid[32+1];
	char devicetoken[64*2];
	
}biz_inpour_t;

//inpour ack
typedef struct biz_inpour_ack_t{
	acs_base_t base;
	char serialnum[32+1];
    char notifyURL[256];
    // char pid[128];
    // char sid[128];
    // char pk[512];
}biz_inpour_ack_t;



#define ACS_ERR_ADDR_EMPTY    3022
#define ACS_ERR_ADDR_NOUSER   3024
#define ACS_ERR_ADD_ADDR      3026
#define ACS_ERR_UPDATE_USER   3028
typedef struct add_addr_t {
	acs_base_t base;
	char username[32+1];
	char attn[32+1];
	char phone[32+1];
	char province[32+1];
	char city[32+1];
	char postcode[6+1];
	char addr[256];
}add_addr_t;

#define ACS_ERR_NO_RECORD  3072
typedef struct my_stuff_t {
	acs_base_t base;
	int type;    //1001,my order ;2001,my address ;3001,my hit record ;4001,my auction;6001:my assets;7001:my inpour record
	int auctprice;
	char username[32+1];//non-cellphone,username only
	char serialnum[32+1];
    
}my_stuff_t;

typedef struct ack_my_stuff_t {
	acs_base_t base;
	int type;//1001,my order ;2001,my address ;3001,my hit record ;4001,my auction
	int count;
	char* list;
}ack_my_stuff_t;

typedef struct assets_t{
    int ballance;
    int points;
    int frozen_sum;
}assets_t;

typedef struct inpour_record_t{
    int inpour_date;
    int status;
    int amt;
    int channel;
    char serialnum[32+1];
    char ex_serialnum[32+1];
}inpour_record_t;

typedef struct addr_t{
	int  created_at;
	int  address_id;
	char attn[32+1];
	char phone[32+1];
	char province[32+1];
	char city[32+1];
	char postcode[32+1];
	char address[32+1];
}addr_t;

typedef struct order_t{
	int status;
	int created_at;
	int type;//1: auction;2:exchange
	int price;
	int points;
	char skucode[32+1];
	char skuname[256];
	char remark[64*2];
	char serialnum[32+1];
	addr_t order_addr;
}order_t;



typedef struct hit_t{
	int auctprice;
	int aucttime;
	char username[32+1];//non-cellphone,username only
}hit_t;


typedef struct auction_record_t{
    int auctprice;
    int created_at;
    int checkflag;
    int hits;
}auction_record_t;

typedef struct auction_t{
    
    int status;
    int sttime;
    int edtime;
    int strikeprice;
    int auction_cnt;
    char userid[32+1];
	char skucode[32+1];
	char skuname[256];
	char serialnum[32+1];
	auction_record_t sublist[3];
}auction_t;


//socket地址
#define SOCKETURL @"121.41.45.147"
//端口
#define SOCKETPOINT 8131

@interface SQSocket : NSObject

@end